package util;

import com.alibaba.fastjson.JSON;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import us.codecraft.webmagic.Request;

import java.io.UnsupportedEncodingException;

public class StringBytes {
    @Test
    public void test() throws UnsupportedEncodingException {
        String key      = "item_www.qichacha.com";
        String field    = "278c85b1117dbafdfb458f5e13d0e0fc55c4ccc9";
        JedisPoolConfig poolConfig = new JedisPoolConfig();

        JedisPool jPool = new JedisPool(poolConfig, "172.16.234.192",6379);
        Jedis jedis = jPool.getResource();
        byte[] bytes    = jedis.hget(key.getBytes(), field.getBytes());
        String json = new String(bytes);
        System.out.println(json);
        System.out.println(JSON.parseObject(json,Request.class));

//        if(bytes != null)
//            return JSON.parseObject(new String(bytes), Request.class);
    }
    @Test
    public void test_fastjson(){

        Group group = new Group();
        group.setId(0L);
        group.setName("admin");

        User guestUser = new User();
        guestUser.setId(2L);
        guestUser.setName("你好");

        User rootUser = new User();
        rootUser.setId(3L);
        rootUser.setName("root");

        group.addUser(guestUser);
        group.addUser(rootUser);

        String jsonString = JSON.toJSONString(group);

        System.out.println(jsonString);
    }
    @Test
    public void test_Base(){
        String a =BaseEncoding.encoding("H189I8A0F5BCNE4D:9D34D77FD49D3FDB");
        System.out.println(a);
    }
}
